<template>
  <div class="contain">
    <div class="header">
      <form :action="url" method="get">
        <el-button type="primary" native-type="submit">批量导出</el-button>
        <input type="hidden" name="renterNameLike"  :value="configList.param.renterNameLike" />
        <input type="hidden" name="gardenNameLike"  :value="configList.param.gardenNameLike" />
        <input type="hidden" name="unitNameLike"  :value="configList.param.unitNameLike" />
        <input type="hidden" name="buildingNameLike"  :value="configList.param.buildingNameLike" />
        <input type="hidden" name="roomIdLike"  :value="configList.param.roomIdLike" />
        <input type="hidden" name="pageSize"  :value="1000" />
        <input type="hidden" name="sessionId"  :value="sessionId" />
      </form>
      <!--<el-button type="primary" @click="addCard()">批量导出</el-button>-->
    </div>
    <div class="input_modal">
      <!--<div class="input-item">-->
        <!--<span>租客：</span>-->
        <!--<el-input v-model="configList.param.renterNameLike" placeholder="请输入内容" class="proName"  @keyup.enter.native="search"></el-input>-->
      <!--</div>-->
      <div class="input-item">
        <span>小区：</span>
        <el-select  v-if="identify == 0" v-model="configList.param.gardenName" placeholder="请选择" @change="handleChangeArea">
          <el-option
            v-for="item in buildingList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-input v-else v-model="configList.param.gardenName" placeholder="请输入内容" class="proName"></el-input>
      </div>
      <div class="input-item">
        <span>单元：</span>
        <el-select  v-if="identify == 0" v-model="configList.param.unitName" placeholder="请选择" @change="handleChangeUnit">
          <el-option
            v-for="item in unitList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-input v-else v-model="configList.param.unitName" placeholder="请输入内容" class="proName"></el-input>
      </div>
      <div class="input-item">
        <span>楼栋：</span>
        <el-select  v-if="identify == 0" v-model="configList.param.buildName" placeholder="请选择" @change="handleChangeBuild">
          <el-option
            v-for="item in buildList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-input v-else v-model="configList.param.buildName" placeholder="请输入内容" class="proName"></el-input>
      </div>
      <div class="input-item">
        <span>租客类型：</span>
        <el-select filterable  v-model="configList.param.rentalType" placeholder="请选择">
          <el-option
            v-for="item in rentArr"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <!--<el-input v-model="configList.param.roomIdLike" placeholder="请输入内容" class="proName"></el-input>-->
      </div>
      <div class="input-item">
        <el-button type="primary" @click="getList()">查询</el-button>
      </div>
    </div>
    <div class="table-content">
      <table-list ref="tableList" :tableConfig='configList' @selectTable="selectTable">
        <el-table-column
          slot="select"  align="center" label="全选"
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column min-width="120px"  align="center">
        </el-table-column>
        <!--<el-table-column slot="content"  align="center" label="公告内容">-->
        <!--<template slot-scope="scope">-->
        <!--<div v-html="scope.row.mobile">{{scope.row.content}}</div>-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column class="btn"  min-width="240px" label="操作" slot="btn" align="center">
          <template slot-scope="scope">
            <el-button  @click="$router.push('/rentalbackDetail?id='+scope.row.id+'&type='+scope.row.rentalType)" type="primary" size="small">查看</el-button>
            <el-button  @click="handleConfirm(scope.row.id, scope.row.rentalId, scope.row.rentalType)" type="primary" size="small" v-if="identify == 0 && (scope.row.rentalBackStatus == 'init')">确认退租</el-button>
            <el-button  @click="handleRefuse(scope.row.id)" type="primary" size="small" v-if="identify == 0 && (scope.row.rentalBackStatus == 'init')">驳回退租</el-button>
            <el-button  @click="$router.push('/rentalbackPrint?id='+scope.row.id+'&type='+scope.row.rentalType)" type="primary" size="small" v-if="identify == 0">打印</el-button>
            <!--<el-button  @click="handleConfirm(scope.row.id, scope.row.rentalBackStatus, scope.row.rentalType)" type="primary" size="small" v-if="identify == 0 && (scope.row.rentalBackStatus == 'readouts' || scope.row.rentalBackStatus == 'create')">确认退租</el-button>-->
             <!--<el-button @click="handleRefuse(scope.row.id)" class="search-btn" size="small" type="danger" v-if="identify == 0 && (scope.row.rentalBackStatus == 'create' || scope.row.rentalBackStatus == 'readouts')">驳回</el-button>-->
          </template>
        </el-table-column>
      </table-list>
    </div>
    <el-dialog
      title="设置水电费"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <div>
        <el-form :model="readouts" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="水费" prop="waterReadouts">
            <el-input v-model="readouts.waterReadouts" placeholder="请输入水费"></el-input>
          </el-form-item>
          <el-form-item label="电费" prop="electricReadouts">
            <el-input v-model="readouts.electricReadouts" placeholder="请输入电费"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="dialogVisible = false" style="color: #fff">取 消</el-button>
            <el-button type="primary" @click="handleSureReadouts('ruleForm')">确 定</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  let CONSTANT = require("../../constant/constant.js");
  let common = require("../../common.js");
  export default{
    data(){
      return {
        url: "",
        sessionId: "",
        buildingList: [{
          label: "全部",
          value: null
        }],
        unitList: [{
          label: "全部",
          value: null
        }],
        buildList: [{
          label: "全部",
          value: null
        }],
        rentArr:[{
          label:'全部',
          value:''
        },{
          label:'日租',
          value:'day_rental'
        },{
          label:'长租',
          value:'long_rental'
        },{
          label:'年租',
          value:'year_rental'
        }],
        areaId: "",
        unitId: "",
        buildingId: "",
        configList:{
          url:"",
          configList:[
            {
              slot: "select"
            },
            {
              label:'租客',
              prop:'renterName',
            },
            {
              label:'小区',
              prop:'gardenName',
            },
            {
              label:'单元',
              prop:'unitName',
            },
            {
              label:'楼栋',
              prop:'buildName',
            },
            {
              label:'房间号',
              prop:'roomId',
            },
            {
              label:'租客类型',
              prop:'rentalTypeText',
            },
            {
              label:'联系电话',
              prop:'renterMobile',
            },
            {
              slot:'btn'
            }
          ],
          param:{
            buildName: "",
            gardenName: "",
            unitName: "",
            renterNameLike: "",
            roomIdLike: "",

          },
          type:'',
          width:'',
          isPagination:true
        },
        identify: "",
        dialogVisible: false,
        readouts: {
          waterReadouts: "",
          electricReadouts: ""
        },
        id: "",
        rules: {
          waterReadouts: [
            {required: true, message: '请输入水费', trigger: 'blur'},
          ],
          electricReadouts: [
            {required: true, message: '请输入电费', trigger: 'blur'}
          ]
        }
      }
    },
    components: {
      'table-list':() => import('../common/my-table')
    },
    created() {
      this.identify = sessionStorage.getItem("identify")
      this.configList.url = this.identify == 1 ? CONSTANT.URL.RENTALBACK.LIST : CONSTANT.URL.L_RENTALBACK.LIST;
    },
    mounted() {
      this.sessionId = sessionStorage.getItem('sessionId');
      this.url = this.identify == 0 ? CONSTANT.URL.L_RENTALBACK.EXPORT : CONSTANT.URL.RENTALBACK.EXPORT
      this.getGardenList()
    },
    methods: {
      getList(){
        this.$refs.tableList.getList()
      },
      selectTable() {

      },
      getGardenList() {
        let url = this.identify == 1 ? '' : CONSTANT.URL.L_HOUSE.L_GARDEN;
        common.requestAjax(url, {}, {}, (data) => {
          if (data.status ==200) {
            data.data.bussData.map( item => {
              this.buildingList.push({
                label: item,
                value: item
              })
            })
          }
        })
      },
      getUnitList() {
        let url = CONSTANT.URL.L_HOUSE.L_UNIT;
        this.unitList = []
        common.requestAjax(url, {}, {gardenName: this.configList.param.gardenName}, (data) => {
          if (data.status ==200) {
            data.data.bussData.map( item => {
              this.unitList.push({
                label: item,
                value: item
              })
            })
          }
        })
      },
      getBuildingList() {
        let url = CONSTANT.URL.L_HOUSE.L_BUILD;
        this.buildList = []
        common.requestAjax(url, {}, {unitName: this.configList.param.unitName}, (data) => {
          if (data.status ==200) {
            data.data.bussData.map( item => {
              this.buildList.push({
                label: item,
                value: item
              })
            })
          }
        })
      },
      handleChangeArea() {
        this.configList.param.unitName = "";
        this.configList.param.buildName = "";
        this.getUnitList()
      },
      handleChangeUnit() {
        this.configList.param.buildName = "";
        this.getBuildingList()
      },
      handleChangeBuild() {

      },
      handleCreate(id, status) {
        let url = CONSTANT.URL.L_RENTALBACK.CREATE;
        common.requestAjax(url, {}, {rentalId: id}, (data) => {
          if (data.status == 200) {
            this.$message({
              type: "success",
              message: data.msg
            })
            this.getList()
          }
          if (data.status == 500) {
            this.$message({
              type: "warning",
              message: data.msg
            })
          }
        })
      },
      handleReadouts(id, status, type) {
        let url = CONSTANT.URL.L_RENTALBACK.READOUTS;
        if (type == "day_rental") {
            common.requestAjax(url, {}, {id: id}, (data) => {
              if (data.status == 200) {
                this.$message({
                  type: "success",
                  message: data.msg
                })
                this.getList()
              }
            })
        } else {
            this.readouts = {
              waterReadouts: "",
              electricReadouts: ""
            }
            this.dialogVisible = true
            this.id = id
        }
      },
      handleClose() {
        this.dialogVisible = false
      },
      handleSureReadouts(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let url = CONSTANT.URL.L_RENTALBACK.READOUTS;
            let params = Object.assign({id: this.id}, this.readouts)
            common.requestAjax(url, {}, params, (data) => {
              if (data.status == 200) {
                this.$message({
                  type: "success",
                  message: data.msg
                })
                this.dialogVisible = false
                this.readouts = {
                  waterReadouts: "",
                  electricReadouts: ""
                }
                this.getList()
              }
              if (data.status == 500) {
                this.$message({
                  type: "warning",
                  message: data.msg
                })
              }
            })

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      handleConfirm(id, rentalId, type) {
          this.$router.push("/rentalbackDetail?id="+id+"&type="+type+"&confirm=1"+"&rentalId="+rentalId)
      },
      handleRefuse(id){
        this.$confirm('确定驳回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let  url = CONSTANT.URL.L_RENTALBACK.REFUSED;
          let data = {id:id} ;
          common.requestAjax(url,{},data,(res)=>{
            if(res.status == 200){
              this.$message({
                type:'success',
                message: res.msg
              });
              this.getList();
            }
            else{
              this.$message({
                type:'warning',
                message:res.msg
              })
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
      //新增编辑
      addCard(id){
        this.$router.push({path:'/informationDetail',query:{'id':id}});
      },
    },
  }
</script>

<style lang="scss">
  .contain {
    .el-dialog__body{ padding-left: 0;padding-top: 30px;border-top:1px solid #dedede;}
    .dialog-con{
      background-color: #f5f5f5;
      display: flex;
      justify-content: space-between;
      ul{
        width:28%;list-style: none;padding:0;font-size:14px;float: left;margin-top:0;z-index:999;
        li{ list-style: none;height:60px;line-height:60px;text-align: center;display: block;}
        li.active{color:#21b5cc;background-color: #fff;font-size:16px;border-right:2px solid #21b5cc;}
        //   li:hover{font-size:16px; }
      }
      .tab-content{ width: 70%;display: inline-block;padding-left:10%;background-color: #fff;min-height:300px;
        .sort{
          .sort_name{ font-weight: 600;margin-bottom: 5px;}
          .group-list{ padding-left: 20px;
            .el-radio{display:block;margin-left: 0;margin-bottom: 3px;}
          }
        }
      }
      .el-button--default{background-color: #fff !important;}
    }
  }
</style>
